<?php

namespace api\components;

use Yii;
use yii\helpers\ArrayHelper;

class EventCenter
{
    public $host;
    public $appId;
    public $appKey;

    const EVENT_TYPES = '/out-api/event-type/get-event-types';
    /**
     * 获取案件分类
     */
    public function getEventTypes($userId, $source = '12319')
    {
        $timeStamp = time();
        $sign = md5($this->appId . $this->appKey . $timeStamp);
        $params = [
            'app_id' => $this->appId,
            'timestamp' => $timeStamp,
            'sign' => $sign,
            'user_id' => $userId,
        ];
        $url = $this->host . self::EVENT_TYPES;
        $response = Yii::$app->curl->get($url, $params);
        if ($response) {
            if (ArrayHelper::getValue($response, 'code', 1) !== 0) {
                $message = ArrayHelper::getValue($response, 'message');
                throw new \Exception($message);
            }
            return $response['data'];
        } else {
            return [];
        }
    }
}
